<template>
	<view>
		<view style="margin-top: 15px;">
			<mix-tree
				:list="listData.dataList"
				:columns="listData.columns"
				:rightButton="listData.rightButtonList"
				@treeItemClick="treeItemClick">
			</mix-tree>
		</view>
		<view class="top-button" style="margin-top: 15px;">
			<navigator
				:key="key"
				v-for="(item,key) in listData.topButtonList"
				:url="
					'/pages/core/ibuilder/ibuilder_'
					+ item.pageData.modalType
					+ '?title='
					+ item.title
					+ '&api='
					+ item.pageData.api + item.pageData.apiParams"
				hover-class="navigator-hover">
				<button type="default">
					{{item.title}}
				</button>
			</navigator>
		</view>
	</view>
</template>

<script>
	import mixTree from '@/components/mix-tree/mix-tree';
	export default {
        name: 'xyBuilderList',
		components: {
			mixTree
        },
        props: {
			api: '',
			cloudId: 0,
			eid: 0,
			show: false,
			predata: {}
		},
		data() {
			return {
				listData: {}
			}
		},
		created() {
            if (this.predata) {
				this.listData = this.predata;
			} else {
				this.loadData();
			}
        },
        watch: {
            api(val) {
                this.loadData();
            },
            show(val) {
                if (val == true) {
                    this.loadData();
                }
            }
        },
		methods: {
            async loadData(){
                let res = await this.util.request({
                    url: this.api,
                    method: 'get',
                });
                // console.log(res)
                if (res.code == 200) {
                    this.listData = res.data.listData
                } else{
                    this.util.showToast({
                        title: res.msg,
                        icon: 'loading',
                        duration: 3000
                    });
                }
            },
			// 点击最后一级时触发该事件
			treeItemClick(item) {
				console.log(item)
			}
		}
	}
</script>

<style>

</style>
